#include <bits/stdc++.h>
#define int long long
#define ps putchar(' ')
#define pe putchar('\n')
using namespace std;
inline char gc()
{
    static char buf[1000000], *p1 = buf, *p2 = buf;
    return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++;
}
inline int read()
{
    int sum = 0, f = 0;
    char ch = gc();
    for (; !isdigit(ch); ch = gc())
        f |= (ch == '-');
    for (; isdigit(ch); ch = gc())
        sum = ((sum << 1) + (sum << 3) + (ch ^ 48));
    return f ? -sum : sum;
}
void write(int x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        write(x / 10);
    putchar(48 + x % 10);
}
const int N = 1e7 + 5, mod = 1e9 + 7;
int n, k, a[N];
signed main()
{
    freopen("knight.in", "r", stdin);
    freopen("knight.out", "w", stdout);
    n = read(), k = read();
    auto qpow = [](int x, int p)
    {
        int ans = 1;
        while (p)
        {
            if (p & 1)
                ans = ans * x % 1000000007;
            x = x * x % 1000000007, p >>= 1;
        }
        return ans;
    };
    int ans = 0;
    for (int i = 1, res = 0, mx = 0; i <= n; ++i)
    {
        res -= mx;
        res += (mx = max(mx, read()));
        ans = (ans + qpow(23, n - i) * res % mod) % mod;
        if (i % k == 0)
            mx = 0;
    }
    write(ans);
    // vector<int> v;
    // auto Read = [&]()
    // {
    //     int x;
    //     while (cin >> x)
    //         v.push_back(x);
    // };
    // auto qpow = [](int x, int p)
    // {
    //     int ans = 1;
    //     while (p)
    //     {
    //         if (p & 1)
    //             ans = ans * x % 1000000007;
    //         x = x * x % 1000000007, p >>= 1;
    //     }
    //     return ans;
    // };
    // Read();
    // int ans = 0, cnt = 0;
    // for (int i : v)
    //     ans = (ans + qpow(23, (int)v.size() - ++cnt) * i % 1000000007) % 1000000007;
    // write(ans);
    return 0;
}